#include "key_task1.h"


#define KEY1        HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)  
#define KEY2        HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_14)  
#define con_key_u_delay  2
#define con_key_d_delay  2







void key_scan()
{
	key.all = 0xff;
	if (KEY1 == 0)
	{
		 key.all = 0xfe; 
	}
	else if (KEY2==0)
	{
		key.all = 0xfd; 
	}
	if (key.all != 0xff)
	{
		key_d_delay++;
		key_u_delay = 0;
		if (key_d_delay>con_key_d_delay)
		{
			bt.one.key_d_s = 1;
			key_temp = key.all;
		}
	}
	else
	{
		key_d_delay = 0;
		if (bt.one.key_d_s == 1)
		{
			key_u_delay++;
			if (key_u_delay>con_key_u_delay)
			{
				bt.one.key_d_s = 0;
				bt.one.key_u_s = 1;
				key_u_delay = 0;
			}
		}

		if (bt.one.key_u_s == 1)
		{
			bt.one.key_u_s = 0;
			switch (key_temp)
			{
					case 0xfe: key_num = 1; break;
					case 0xfd: key_num = 2; break;
					case 0xfb: key_num = 3; break;
					default: key_num = 0; break;
			}
		}
		else key_num = 0;
	}
}

 




void task1_init(){
	 GPIO_InitTypeDef GPIO_InitStruct = {0};
		__HAL_RCC_GPIOC_CLK_ENABLE();
		GPIO_InitStruct.Pin =GPIO_PIN_13| GPIO_PIN_14|GPIO_PIN_15;
		GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
		GPIO_InitStruct.Pull = GPIO_PULLUP;
		HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
	 
	 		__HAL_RCC_GPIOC_CLK_ENABLE();
}



void key_task1()
{
	 WHILE(1){
		 
				//key_scan();
	 }
}




void start_key_task1(){
  	//task1_init();
	// OSTaskCreate(key_task1);
}


